// 生产环境打包配置
/* eslint-disable */
const path = require('path');
const { merge } = require('webpack-merge');
// 清除目录
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
// 静态文件复制
const CopyWebpackPlugin = require('copy-webpack-plugin');
// 压缩css
const OptimizeWebpackPlugin = require('optimize-css-assets-webpack-plugin');
// css提出
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// 打包文件分析
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
// eslint
const EslintWebpackPlugin = require('eslint-webpack-plugin');

const common = require('./webpack.common');

module.exports = merge(common, {
  mode: 'production',
  devtool: false,
  output: {
    filename: '[name].[contenthash:8].bundle.js', // 输出文件名
    path: path.join(__dirname, 'dist'), // 输出文件目录
  },
  plugins: [
    new CleanWebpackPlugin(),
    new MiniCssExtractPlugin({
      filename: 'css/[name].[contenthash:8].bundle.css',
      chunkFilename: 'css/[name].[contenthash:8].bundle.css',
      ignoreOrder: true,
    }),
    new OptimizeWebpackPlugin(),
    new CopyWebpackPlugin({
      patterns: [
        { from: path.resolve('public/favicon.ico'), to: '' },
      ],
    }),
    // eslint插件
    // new EslintWebpackPlugin({
    //     files: ['src/**/*.(vue|js)'],
    //     failOnError: true,
    //     failOnWarning: false,
    // })

    // 打包分析插件
    // new BundleAnalyzerPlugin(),
  ],
});
